package com.itheima.commons.vo.reception;

/**
 * @author yaohu
 * @date 2021/12/6
 * @Version 1.0
 * @describe
 */

import cn.hutool.core.util.ObjectUtil;
import com.itheima.commons.pojo.mongo.RecommendUser;
import com.itheima.commons.pojo.domain.UserInfo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 今日佳人
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class TodayBest {

    private Long id; //用户id
    private String avatar;
    private String nickname;
    private String gender; //性别 man woman
    private Integer age;
    private String[] tags;
    private Long fateValue; //缘分值

    /**
     * 在vo对象中，补充一个工具方法，封装转化过程
     */
    public static TodayBest init(UserInfo userInfo, RecommendUser recommendUser) {
        if (ObjectUtil.isNull(userInfo)) {
            return null;
        }

        TodayBest vo = TodayBest.builder()
                .id(userInfo.getUserId())
                .avatar(userInfo.getLogo())
                .nickname(userInfo.getNickName())
                .gender(userInfo.getSex() == 1 ? "man" : "woman")
                .age(userInfo.getAge())
                .fateValue(recommendUser.getScore().longValue())
                .build();

        if (userInfo.getTags() != null) {
            vo.setTags(userInfo.getTags().split(","));
        }

        return vo;
    }
}
